package com.vhans.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vhans.core.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.vhans.db.service.IBaseService;
import com.vhans.core.web.model.Result;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.base.BaseDTO;
import com.vhans.db.model.vo.base.*;
import com.vhans.core.web.page.TableDataInfo;

import java.util.List;

/**
 * 基本属性Controller控制器
 * 
 * @author vhans
 * @date 2023-05-20
 */
@Api(tags = "基本属性模块")
@RestController
@RequestMapping("/dome/base")
public class BasesController extends BaseController {
    @Autowired
    private IBaseService baseService;

    /**
     * 查询基本属性列表
     * @param condition 条件
     * @return {@link BaseVO} 题目列表
     */
    @ApiOperation(value = "查询基本属性列表")
    @SaCheckPermission("dome:base:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<BaseVO> list = baseService.selectBaseVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取基本属性详细信息
     * @param id 基本属性id
     * @return {@link Result<BaseInfoVO>} 基本属性信息
     */
    @ApiOperation(value = "获取基本属性编辑信息")
    @SaCheckPermission("dome:base:query")
    @GetMapping(value = "/info/{id}")
    public Result<BaseInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(baseService.selectBaseInfoById(id));
    }

    /**
     * 新增基本属性
     *
     * @param base 基本属性信息
     * @return {@link Result<>}
     */
    @ApiOperation(value = "新增基本属性")
    @SaCheckPermission("dome:base:add")
    @PostMapping("/add")
    public Result<Integer> add(@Validated @RequestBody BaseDTO base) {
        int id = baseService.insertBase(base);
        return Result.success(id);
    }

    /**
     * 修改基本属性
     */
    @ApiOperation(value = "修改基本属性")
    @SaCheckPermission("dome:base:update")
    @PutMapping("/update")
    public Result<?> update(@Validated @RequestBody BaseDTO base) {
        baseService.updateBase(base);
        return Result.success();
    }

    /**
     * 删除基本属性
     *
     * @param idList 需要删除的基本属性主键列表
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除基本属性")
    @SaCheckPermission("dome:base:delete")
	@DeleteMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> idList) {
        return toAjax(baseService.deleteBaseByIdIdList(idList));
    }
}
